<link rel="import" href="chrome://resources/html/polymer.html">

<link rel="import" href="chrome://resources/cr_elements/cr_icons_css.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
<link rel="import" href="chrome://resources/cr_elements/icons.html">
<link rel="import" href="chrome://resources/cr_elements/paper_button_style_css.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="chrome://resources/html/action_link.html">
<link rel="import" href="chrome://resources/html/action_link_css.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-progress/paper-progress.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-styles/color.html">
<link rel="import" href="chrome://downloads/browser_proxy.html">
<link rel="import" href="chrome://downloads/constants.html">
<link rel="import" href="chrome://downloads/i18n_setup.html">
<link rel="import" href="chrome://downloads/icons.html">

<dom-module id="downloads-item">
  <template>
    <style include="action-link cr-hidden-style cr-icons paper-button-style">
      :host {
        display: flex;
        flex-direction: column;
      }

      paper-button {
        font-weight: 500;
        margin: 0;
        min-width: auto;
        width: 30px;
        height: 20px;
      }

      #date {
        color: var(--google-grey-900);
        font-size: 0.875rem;
        font-weight: 400;
        letter-spacing: .25px;
        line-height: 38px;
        margin: 0;
        width: 100%;
      }

      #date:empty {
        display: none;
      }

      #content {
        width: 99%;              
        background: white;
        border-radius: var(--cr-card-border-radius);
        display: flex;
        flex: none;
        margin: 6px auto;
        height: 76px;
        position: relative;

      }

      #content.is-active {
        @apply --cr-card-elevation;
      }

      #content:not(.is-active) {
        background: rgba(255, 255, 255, .6);
        border: 1px var(--google-grey-300) solid;
      }

      #details {
        /* -webkit-border-start: 1px #d8d8d8 solid; */
        
        display: block;
        flex: 1;
        flex-direction: column;
        width: 100%;
        box-sizing: border-box;
        min-width: 0;
        /* This allows #url to ellide correctly. */
        /* padding-bottom: 12px;
        padding-top: 16px; */
      }

      #content:not(.is-active) {
        color: rgba(27, 27, 27, .6);
      }

      #content:not(.is-active) #name {
        text-decoration: line-through;
      }

      .icon-wrapper {
        align-self: center;
        flex: none;
        flex: none;
        justify-content: center;
        margin: 0 18px 0 35px;
        position: relative;
      }

      .icon-wrapper span.circle{
        display: inline-block;
        width: 5px;
        height: 5px;
        background: #1a73e8;
        border-radius: 50%;
        top: 36px;
        left: -15px;
        position: absolute;
      }

      .icon {
        height: 40px;
        width: 40px;
      }

      #content:-webkit-any(.show-progress, .dangerous) #file-icon-wrapper {
        /* TODO(dbeam): animate from top-aligned to centered when items finish?
         */
        align-self: flex-start;
        padding-top: 16px;
      }

      #content:not(.is-active) .icon {
        -webkit-filter: grayscale(100%);
        opacity: .5;
      }

      #danger-icon {
        height: 32px;
        width: 32px;
      }

      #danger-icon[icon='cr:warning'],
      .dangerous #description {
        color: var(--google-red-700);
      }

      #name,
      #file-link,
      #url {
        max-width: 100%;
      }

      #name,
      #file-link {
        font-weight: 500;
        word-break: break-all;

      }

      .is-active :-webkit-any(#name, #file-link, #show) {
        color: var(--google-blue-600);
      }

      #name {
        -webkit-margin-end: 12px;
        /* Only really affects #tag. */
      }

      #tag {
        color: #5a5a5a;
        font-weight: 500;
      }

      #url {
        color: inherit;
        margin-top: 6px;
        min-height: 0;
        overflow: hidden;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .is-active #url {
        color: var(--cr-secondary-text-color);
      }

      #progress,
      #description:not(:empty),
      .controls {
        margin-top: 16px;
      }

      .is-active #description {
        color: #616161;
      }

      #progress {
        --paper-progress-active-color: var(--google-blue-600);
        --paper-progress-container-color: rgb(223, 222, 223);
        width: auto;
      }

      #show {
        margin: .7em 0;
      }

      #controlled-by {
        -webkit-margin-start: 8px;
      }

      #controlled-by,
      #controlled-by a {
        color: #5a5a5a;
      }

      .is-active #controlled-by {
        color: #333;
      }

      .is-active #controlled-by a {
        color: var(--google-blue-600);
      }

      #remove-wrapper {
        align-self: flex-start;
        margin: 0;

      }

      #remove-wrapper>paper-icon-button-light {
        -webkit-margin-end: 0;
        -webkit-margin-start: 0;
        color: var(--google-grey-refresh-700);
        height: 32px;
        width: 32px;
      }

      #incognito {
        bottom: 20px;
        content: -webkit-image-set( url(chrome://downloads/1x/incognito_marker.png) 1x,
        url(chrome://downloads/2x/incognito_marker.png) 2x);
        position: absolute;
        right: 10px;
      }

      #title-area {
        float: left;
        width: 20%;
        line-height: 53px;
        min-width: 140px;
        overflow: hidden;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: none;
      }

      a#url {
        display: none;
      }

      div.progressBox {
        float: left;
        width: 100%;

      }

      div#description {
        margin-top: 5px;
      }

      div#description::after{
        content:'';
        display: block;
        height: 0;
        width: 100%;
        clear: both;
      }

      span.datafilename {
        text-align: left;
        width: 50%;
        float:left;
        height: 20px;
        line-height: 20px;
      }

      span.datafilepro {
        float: left;
        width: 50%;
        height: 20px;
        line-height: 20px;
      }

      span.datafilepro>*{
        float:left;
      }

      span.datafilepro span.sys{
        width: 20%;
      }

      span.datafilepro #progress{
        width: 50%;
        margin-top: 8px;
      }

      span.datafilepro div.controls{
        float:right;
        height: 20px;
        margin-top: -3px;
      }

      /*  */

      @media screen and (min-width: 480px) {}

      @media screen and (min-width: 768px) {
        div.progressBox {
          width: 100%;
        }

      }

    div.item{position: relative;width: 100%;margin-bottom: 10px;color:#1a73e8 ;background: #ffffff;height: 32px;overflow: hidden;box-sizing: border-box; padding-left: 120px;padding-right: 122px; border-bottom: 1px solid rgb(220, 222, 226) ;padding-bottom: 10px}
    div.item>*{float: left;}
    div.item span.fileName{width: 90%;margin-left: -120px;height: 32px;line-height: 32px;box-sizing: border-box;padding-left: 10px;}
    div.item span.progress{width: 10%;height: 32px;line-height: 32px;}
    div.item span.progress_complete{width: auto;height: 32px;margin-left:32px;line-height: 32px;}

    div.item span.btnDownLoad{width: auto;margin-right: -110px;height: 26px;margin-top: 2px;border: 1px solid rgb(220, 222, 226);
      background: #ffffff;
      border-radius: 4px;
      padding: 0 8px;
      line-height: 26px;
      cursor: pointer;
      color: #1a73e8;
      float: right;
    }
    div.item span.btnDownLoad:hover{background: rgba(26,115,232,0.8);color: #ffffff;}

    div.filePath{color: #cccccc;width: 100%;margin-top: 5px;}
    div.filePath span.time{float:right;}
    </style>

    <h3 id="date">[[computeDate_(data.hideDate, data.since_string, data.date_string)]]</h3>
    <div id="content" on-dragstart="onDragStart_" class$="[[computeClass_(isActive_, isDangerous_, showProgress_)]]">
      <!-- 下载头部内容 -->
      <div id="file-icon-wrapper" class="icon-wrapper">
        <span class="circle"></span>
        <img class="icon" id="file-icon" alt="" hidden="[[isDangerous_]]">
        <iron-icon id="danger-icon" icon$="[[computeDangerIcon_(isDangerous_, data.danger_type)]]" hidden="[[!isDangerous_]]"></iron-icon>
      </div>
      <!-- 下载详情内容 -->
      <div id="details">
        <!-- 标题已经移除 ,不起效果 -->
        <div id="title-area">
          <!--
          Can't have any line breaks.
          -->
          <a is="action-link" id="file-link" href="[[data.url]]" on-click="onFileLinkTap_" hidden="[[!completelyOnDisk_]]">[[data.file_name]]</a>
          <!--
          Before #name.
          -->
          <span id="name" hidden="[[completelyOnDisk_]]">[[data.file_name]]</span>
          <span id="tag">[[computeTag_(data.state, data.last_reason_text, data.file_externally_removed)]]</span>
        </div>

        <a id="url" target="_blank">[[chopUrl_(data.url)]]</a>
        <div class="progressBox">
          <!-- 文件名 -->
          <div id="description">
            <span class="datafilename">[[data.file_name]]</span>
            <template is="dom-if" if="[[!showProgress_]]"> 
                <template is="dom-if" if="[[showCancel_]]"> 
                    <span class="datafilepro">已完成</span>
                </template>
                <template is="dom-if" if="[[!showCancel_]]"> 
                    <span class="datafilepro">已取消</span>
                </template>
            </template>
            <span class="datafilepro">
              <span class="sys">47kb/s</span><!-- [[computeDescription_( data.danger_type, data.file_name, data.progress_status_text)]]-->
              <template is="dom-if" if="[[showProgress_]]">
                <paper-progress id="progress" indeterminate="[[isIndeterminate_(data.percent)]]" value="[[data.percent]]"></paper-progress>
              </template>
              <div id="safe" class="controls" hidden="[[isDangerous_]]">
                  <!-- 在文件夹显示   官方 -->
                  <template is="dom-if" if="[[!data.complete]]">
                    <a is="action-link" id="show" on-click="onShowTap_"   hidden="[[!completelyOnDisk_]]">$i18n{controlShowInFolder}</a>
                  </template>
               
                  
                  <template is="dom-if" if="[[data.complete]]">
                    <!-- 打开文件列表 我们的 -->     
                    <span on-click="openFile" style="color: #1a73e8 ;margin-top:10px;cursor:pointer">{{isOpenFile}}</button>
                  </template>
                  <!-- 重试 -->
                  <template is="dom-if" if="[[data.retry]]">
                    <paper-button class="action-button" on-click="onRetryTap_">
                      $i18n{controlRetry}
                    </paper-button>
                  </template>
                  <!-- 暂停    -->
                  <template is="dom-if" if="[[pauseOrResumeText_]]" style="width: 50%">
                    <paper-button class$="[[pauseOrResumeClass_]]" on-click="onPauseOrResumeTap_">
                     <!-- [[pauseOrResumeText_]] -->
                     <img src="">
                    </paper-button>
                  </template>
                  <!-- 继续 -->
                  <template is="dom-if" if="[[!pauseOrResumeText_]]" style="width: 50%">
                      <paper-button class$="[[pauseOrResumeClass_]]" on-click="onPauseOrResumeTap_">
                       <!-- [[pauseOrResumeText_]] -->
                       <img src="">
                      </paper-button>
                    </template>
                  <!-- 取消 -->
                  <template is="dom-if" if="[[showCancel_]]">
                    <template is="dom-if" if="[[showProgress_]]">
                      <paper-button on-click="onCancelTap_">
                        <!-- $i18n{controlCancel} -->
                        <img src="">
                      </paper-button>
                    </template>
                  </template>
                  <span id="controlled-by" style="margin: 0;">
                    Text populated dynamically. -->
                  </span>
                </div>
            </span>
          </div>
          <!-- <template is="dom-if" if="[[showProgress_]]"></template> -->
          <div class="filePath">
            <span class="path">[[chopUrl_(data.url)]]</span>
            <span class="time">2018-08-23 22:22:11</span>
          </div>
          <template is="dom-if" if="[[!showProgress_]]"> 
              <template is="dom-if" if="[[!showCancel_]]"> 
                  <paper-progress  id="progress" indeterminate="[[isIndeterminate_(data.percent)]]" value="0"></paper-progress>
              </template>
              <template is="dom-if" if="[[showCancel_]]"> 
                  <paper-progress  id="progress" indeterminate="[[isIndeterminate_(data.percent)]]" value="100"></paper-progress>
              </template>
          
          </template>
          
        </div>

        

        <template is="dom-if" if="[[isDangerous_]]">
          <div id="dangerous" class="controls">
            <!-- Dangerous file types (e.g. .exe, .jar). -->
            <template is="dom-if" if="[[!isMalware_]]">
              <!-- 放弃 -->
              <paper-button on-click="onDiscardDangerousTap_" class="action-button">$i18n{dangerDiscard}</paper-button>
              <!-- 保存 -->
              <paper-button on-click="onSaveDangerousTap_">
                $i18n{dangerSave}</paper-button>
            </template>
            <!-- 底部的放弃和保存 -->
            <!-- Things that safe browsing has determined to be dangerous. -->
            <template is="dom-if" if="[[isMalware_]]">
              <paper-button on-click="onDiscardDangerousTap_" class="action-button">
                $i18n{controlRemoveFromList}</paper-button>
              <paper-button on-click="onSaveDangerousTap_">
                $i18n{dangerRestore}</paper-button>
            </template>
          </div>
        </template>
      </div>
      <!-- 下载删除 -->
      <div id="remove-wrapper" class="icon-wrapper ">
        <paper-icon-button-light class="icon-clear" style$="[[computeRemoveStyle_(isDangerous_, showCancel_)]]">
          <button id="remove" title="$i18n{controlRemoveFromList}" aria-label="$i18n{controlRemoveFromList}" on-click="onRemoveTap_"></button>
        </paper-icon-button-light>
      </div>

      <div id="incognito" title="$i18n{inIncognito}" hidden="[[!data.otr]]">
      </div>
    </div>
    <!-- 需要打开文件列表 -->

    <template is="dom-if" if={{isFileUrlList}} > 
        <div style="background: white ; width: 50%;margin: 0 0 0 25%;">
        <template is="dom-repeat" items="[[data.files]]" hidden={{isFileUrlList}}>
          <div >
            <div class="item">
              <span class="fileName">[[item.fileName]] </span>
              <span class="progress">[[item.size]]M</span>
              <span class="progress_complete">已完成</span>
              <span type="button" class="btnDownLoad"><a is="action-link" href=[[item.url]] download=[[item.fileName]]>点击下载</a></span>
            </div>
          </div>
        </template>
      </template>  
        
</div>
    </template>
  

  
  <script src="chrome://downloads/item.js"></script>
</dom-module>

